/**
 * 网站 MongoDB Schema
 */

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type WebsiteDocument = Website & Document;

@Schema({ collection: 'websites', timestamps: true })
export class Website {
  @Prop({ required: true, maxlength: 100 })
  domain: string;

  @Prop({ required: true, maxlength: 255 })
  name: string;

  @Prop()
  description?: string;

  @Prop({ default: true })
  isActive: boolean;

  @Prop({ maxlength: 64, index: true })
  trackingId?: string;

  @Prop({ default: false })
  ignoreLocalhost: boolean;

  @Prop({ default: true })
  collectIp: boolean;

  @Prop({ default: true })
  collectUserAgent: boolean;

  @Prop({ default: true })
  collectReferrer: boolean;

  // MongoDB 自动生成的字段
  createdAt?: Date;
  updatedAt?: Date;
}

export const WebsiteSchema = SchemaFactory.createForClass(Website);

// 创建索引
WebsiteSchema.index({ domain: 1 }); // 普通索引，不唯一
WebsiteSchema.index({ trackingId: 1 });
WebsiteSchema.index({ isActive: 1 });
